<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flowable DMN 决策测试页面</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        .section {
            margin-bottom: 40px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
            background-color: #fafafa;
        }
        .section h2 {
            color: #2c3e50;
            margin-top: 0;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #555;
        }
        input, select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }
        button {
            background-color: #3498db;
            color: white;
            padding: 12px 24px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            margin-right: 10px;
            margin-bottom: 10px;
        }
        button:hover {
            background-color: #2980b9;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            background-color: #e8f5e8;
            border: 1px solid #4caf50;
            border-radius: 4px;
            white-space: pre-wrap;
            font-family: monospace;
        }
        .error {
            background-color: #ffebee;
            border-color: #f44336;
            color: #c62828;
        }
        .grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
        }
        .example-buttons {
            text-align: center;
            margin: 20px 0;
        }
        .example-buttons button {
            background-color: #27ae60;
            margin: 5px;
        }
        .example-buttons button:hover {
            background-color: #229954;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🚀 Flowable DMN 决策引擎测试页面</h1>
        
        <div class="example-buttons">
            <button onclick="testAllDecisions()">🧪 测试所有决策</button>
            <button onclick="loadExampleData()">📋 加载示例数据</button>
            <button onclick="clearAll()">🗑️ 清空所有</button>
        </div>

        <div class="grid">
            <!-- 请假审批决策 -->
            <div class="section">
                <h2>📋 请假审批决策</h2>
                <div class="form-group">
                    <label for="employee">员工姓名:</label>
                    <input type="text" id="employee" value="张三">
                </div>
                <div class="form-group">
                    <label for="employeeLevel">员工级别:</label>
                    <select id="employeeLevel">
                        <option value="普通员工">普通员工</option>
                        <option value="主管">主管</option>
                        <option value="经理">经理</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="days">请假天数:</label>
                    <input type="number" id="days" value="3" min="1" max="30">
                </div>
                <div class="form-group">
                    <label for="leaveType">请假类型:</label>
                    <select id="leaveType">
                        <option value="病假">病假</option>
                        <option value="事假">事假</option>
                        <option value="年假">年假</option>
                    </select>
                </div>
                <button onclick="testLeaveApproval()">执行请假审批决策</button>
                <div id="leaveResult" class="result" style="display: none;"></div>
            </div>

            <!-- 风险评估决策 -->
            <div class="section">
                <h2>⚠️ 项目风险评估决策</h2>
                <div class="form-group">
                    <label for="projectType">项目类型:</label>
                    <select id="projectType">
                        <option value="软件开发">软件开发</option>
                        <option value="基础设施">基础设施</option>
                        <option value="研究">研究</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="budget">项目预算 (元):</label>
                    <input type="number" id="budget" value="100000" min="0">
                </div>
                <div class="form-group">
                    <label for="teamSize">团队规模 (人):</label>
                    <input type="number" id="teamSize" value="5" min="1" max="50">
                </div>
                <div class="form-group">
                    <label for="experience">团队经验:</label>
                    <select id="experience">
                        <option value="初级">初级</option>
                        <option value="中级">中级</option>
                        <option value="高级">高级</option>
                    </select>
                </div>
                <button onclick="testRiskAssessment()">执行风险评估决策</button>
                <div id="riskResult" class="result" style="display: none;"></div>
            </div>

            <!-- 折扣计算决策 -->
            <div class="section">
                <h2>💰 折扣计算决策</h2>
                <div class="form-group">
                    <label for="customerType">客户类型:</label>
                    <select id="customerType">
                        <option value="新客户">新客户</option>
                        <option value="普通">普通</option>
                        <option value="VIP">VIP</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="orderAmount">订单金额 (元):</label>
                    <input type="number" id="orderAmount" value="2000" min="0" step="0.01">
                </div>
                <div class="form-group">
                    <label for="loyaltyPoints">积分:</label>
                    <input type="number" id="loyaltyPoints" value="500" min="0">
                </div>
                <div class="form-group">
                    <label for="season">季节:</label>
                    <select id="season">
                        <option value="春季">春季</option>
                        <option value="夏季">夏季</option>
                        <option value="秋季">秋季</option>
                        <option value="冬季">冬季</option>
                    </select>
                </div>
                <button onclick="testDiscountCalculation()">执行折扣计算决策</button>
                <div id="discountResult" class="result" style="display: none;"></div>
            </div>
        </div>
    </div>

    <script>
        const API_BASE = '/api/dmn';

        async function testLeaveApproval() {
            const data = {
                employee: document.getElementById('employee').value,
                employeeLevel: document.getElementById('employeeLevel').value,
                days: parseInt(document.getElementById('days').value),
                leaveType: document.getElementById('leaveType').value
            };

            try {
                const response = await fetch(`${API_BASE}/leave-approval`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });

                const result = await response.json();
                displayResult('leaveResult', result);
            } catch (error) {
                displayError('leaveResult', error);
            }
        }

        async function testRiskAssessment() {
            const data = {
                projectType: document.getElementById('projectType').value,
                budget: parseInt(document.getElementById('budget').value),
                teamSize: parseInt(document.getElementById('teamSize').value),
                experience: document.getElementById('experience').value
            };

            try {
                const response = await fetch(`${API_BASE}/risk-assessment`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });

                const result = await response.json();
                displayResult('riskResult', result);
            } catch (error) {
                displayError('riskResult', error);
            }
        }

        async function testDiscountCalculation() {
            const data = {
                customerType: document.getElementById('customerType').value,
                orderAmount: parseFloat(document.getElementById('orderAmount').value),
                loyaltyPoints: parseInt(document.getElementById('loyaltyPoints').value),
                season: document.getElementById('season').value
            };

            try {
                const response = await fetch(`${API_BASE}/discount-calculation`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });

                const result = await response.json();
                displayResult('discountResult', result);
            } catch (error) {
                displayError('discountResult', error);
            }
        }

        async function testAllDecisions() {
            try {
                const response = await fetch(`${API_BASE}/test-all`);
                const result = await response.json();
                
                // 显示所有结果
                displayResult('leaveResult', result.leaveApproval);
                displayResult('riskResult', result.riskAssessment);
                displayResult('discountResult', result.discountCalculation);
            } catch (error) {
                alert('测试失败: ' + error.message);
            }
        }

        function loadExampleData() {
            // 请假审批示例
            document.getElementById('employee').value = '李四';
            document.getElementById('employeeLevel').value = '普通员工';
            document.getElementById('days').value = '5';
            document.getElementById('leaveType').value = '事假';

            // 风险评估示例
            document.getElementById('projectType').value = '软件开发';
            document.getElementById('budget').value = '200000';
            document.getElementById('teamSize').value = '8';
            document.getElementById('experience').value = '中级';

            // 折扣计算示例
            document.getElementById('customerType').value = 'VIP';
            document.getElementById('orderAmount').value = '3000';
            document.getElementById('loyaltyPoints').value = '800';
            document.getElementById('season').value = '春季';
        }

        function clearAll() {
            // 清空所有输入
            document.getElementById('employee').value = '';
            document.getElementById('days').value = '1';
            document.getElementById('budget').value = '0';
            document.getElementById('teamSize').value = '1';
            document.getElementById('orderAmount').value = '0';
            document.getElementById('loyaltyPoints').value = '0';

            // 隐藏所有结果
            document.getElementById('leaveResult').style.display = 'none';
            document.getElementById('riskResult').style.display = 'none';
            document.getElementById('discountResult').style.display = 'none';
        }

        function displayResult(elementId, result) {
            const element = document.getElementById(elementId);
            element.style.display = 'block';
            element.className = 'result';
            element.textContent = JSON.stringify(result, null, 2);
        }

        function displayError(elementId, error) {
            const element = document.getElementById(elementId);
            element.style.display = 'block';
            element.className = 'result error';
            element.textContent = '错误: ' + error.message;
        }
    </script>
</body>
</html>

